//
//  PreviewResumeVC.m
//  MyProject
//
//  Created by jiaming yan on 2017/9/12.
//  Copyright © 2017年 yanjiaming. All rights reserved.
//

#import "PreviewResumeVC.h"
#import "NoVitaeTableViewCell.h"
#import "HeadTableViewCell.h"
#import "PreviewBaseInfoTableViewCell.h"
#import "WorkExperienceTableViewCell.h"
#import "EducationTableViewCell.h"
#import "EducationListVC.h"
//#import "ExpectedWorkTableViewCell.h"
#import "ValuesTableViewCell.h"
#import "ProjectExperienceTableViewCell.h"
#import "SkillTableViewCell.h"
#import "RemarksTableViewCell.h"
#import "BaseInfoVC.h"
#import "WorkExperienceListVC.h"
#import "AddExpectedWorkVC.h"
#import "ProjectExperienceListVC.h"
#import "SkillListVC.h"
#import "DescribeVC.h"
#import "GetResumeByUserIdRootClass.h"
#import "GetComPanyCultureRootClass.h"
#import <QiniuSDK.h>
#import "VitaeTitleHeadView.h"
#import "ResumeModel.h"


#import "NSUDManager.h"
#import "WorkExperienceListModel.h"
#import "EducationModel.h"
#import "ProjectModel.h"
#import "SkillModel.h"

@interface PreviewResumeVC ()<UITableViewDelegate,UITableViewDataSource,UIActionSheetDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSMutableArray *arrData;//图片名数组
@property (strong, nonatomic) NSArray *titleArrData;//标题名数组
@property (strong, nonatomic) ResumeModel *modelUserInfoResume;
@property (strong, nonatomic) NSArray *workExperienceArr;//工作经历数组
@property (strong, nonatomic) NSArray *educationArr;//教育经历数组
@property (strong, nonatomic) NSArray *projectArr;//项目经历数组
@property (strong, nonatomic) NSArray *skillArr;//技能数组

@property (strong, nonatomic) NSMutableArray *arrComPanyCulture;
@property (strong, nonatomic) NSMutableArray *arrComPanyCultureSelect;

@property (assign, nonatomic) BOOL showMore;//是否显示更多
@property (strong, nonatomic) UIButton *moreButton;
@end

@implementation PreviewResumeVC

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self showProgressWithView:self.view animated:YES];
    __weak typeof(self) weakSelf = self;
    [YJMSendRequest postDataWithParameters:@{@"userId":self.user_id} url:@"resume/getResume" result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        [weakSelf hideProgress:self.view animated:YES];
        if([result[@"result"] integerValue] == 1)
        {
           weakSelf.modelUserInfoResume =  [ResumeModel mj_objectWithKeyValues:result[@"data"]];
            
            [weakSelf.tableView reloadData];
        }else{
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
    }];
    
    [self requestWorkExperience];
    [self requestEducationArr];
    [self requestProjectArr];
    [self requestSkillArr];
}
/*
 方法描述:
 工作经验
 
 参数说明:
 <#参数说明#>
 
 返回结果:
 <#返回结果#>
 
 */
-(void)requestWorkExperience{
    
    [self showProgressWithView:self.view animated:YES];
    __weak typeof(self) weakSelf = self;
    [YJMSendRequest postDataWithParameters:@{@"userId":self.user_id} url:@"resume/getWorkExperience" result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        [weakSelf hideProgress:self.view animated:YES];
        if([result[@"result"] integerValue] == 1)
        {
            weakSelf.workExperienceArr =  [WorkExperienceListModel mj_objectArrayWithKeyValuesArray:result[@"data"]];
            [weakSelf.tableView reloadData];
        }else{
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
    }];
}
/*
 方法描述:
 教育经验
 
 参数说明:
 <#参数说明#>
 
 返回结果:
 <#返回结果#>
 
 */
-(void)requestEducationArr{
    
    [self showProgressWithView:self.view animated:YES];
    __weak typeof(self) weakSelf = self;
    [YJMSendRequest postDataWithParameters:@{@"userId":self.user_id} url:@"resume/getEduExperience" result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        [weakSelf hideProgress:self.view animated:YES];
        if([result[@"result"] integerValue] == 1)
        {
            weakSelf.educationArr =  [EducationModel mj_objectArrayWithKeyValuesArray:result[@"data"]];
            [weakSelf.tableView reloadData];
        }else{
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
    }];
}
/*
 方法描述:
 项目经验
 
 参数说明:
 <#参数说明#>
 
 返回结果:
 <#返回结果#>
 
 */
-(void)requestProjectArr{
    
    [self showProgressWithView:self.view animated:YES];
    __weak typeof(self) weakSelf = self;
    [YJMSendRequest postDataWithParameters:@{@"userId":self.user_id} url:@"resume/getProjectExperience" result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        [weakSelf hideProgress:self.view animated:YES];
        if([result[@"result"] integerValue] == 1)
        {
            weakSelf.projectArr =  [ProjectModel mj_objectArrayWithKeyValuesArray:result[@"data"]];
            [weakSelf.tableView reloadData];
        }else{
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
    }];
}
/*
 方法描述:
 技能
 
 参数说明:
 <#参数说明#>
 
 返回结果:
 <#返回结果#>
 
 */
-(void)requestSkillArr{
    
    [self showProgressWithView:self.view animated:YES];
    __weak typeof(self) weakSelf = self;
    [YJMSendRequest postDataWithParameters:@{@"userId":self.user_id} url:@"resume/getCandidateSkills" result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        [weakSelf hideProgress:self.view animated:YES];
        if([result[@"result"] integerValue] == 1)
        {
            weakSelf.skillArr =  [SkillModel mj_objectArrayWithKeyValuesArray:result[@"data"]];
            [weakSelf.tableView reloadData];
        }else{
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"简历预览";
    [self.tableView registerNib:[UINib nibWithNibName:@"NoVitaeTableViewCell" bundle:nil] forCellReuseIdentifier:@"NoVitaeTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"HeadTableViewCell" bundle:nil] forCellReuseIdentifier:@"HeadTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"PreviewBaseInfoTableViewCell" bundle:nil] forCellReuseIdentifier:@"PreviewBaseInfoTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"WorkExperienceTableViewCell" bundle:nil] forCellReuseIdentifier:@"WorkExperienceTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"EducationTableViewCell" bundle:nil] forCellReuseIdentifier:@"EducationTableViewCell"];
    //    [self.tableView registerNib:[UINib nibWithNibName:@"ExpectedWorkTableViewCell" bundle:nil] forCellReuseIdentifier:@"ExpectedWorkTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"ValuesTableViewCell" bundle:nil] forCellReuseIdentifier:@"ValuesTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"ProjectExperienceTableViewCell" bundle:nil] forCellReuseIdentifier:@"ProjectExperienceTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"SkillTableViewCell" bundle:nil] forCellReuseIdentifier:@"SkillTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"RemarksTableViewCell" bundle:nil] forCellReuseIdentifier:@"RemarksTableViewCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"VitaeTitleHeadView" bundle:nil] forHeaderFooterViewReuseIdentifier:@"VitaeTitleHeadView"];
    [self.tableView registerNib:[UINib nibWithNibName:@"VitaeTitleFoodView" bundle:nil] forHeaderFooterViewReuseIdentifier:@"VitaeTitleFoodView"];
    
//    UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 90)];
//    self.moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [self.moreButton setFrame:CGRectMake(15, 20, kScreenWidth - 30, 50)];
//    [self.moreButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
//    [self.moreButton setBackgroundColor:UIColorFromRGB(0X42CDD9)];
//    self.moreButton.clipsToBounds = YES;
//    self.moreButton.layer.cornerRadius = 10;
//    self.moreButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
//    [self.moreButton setImage:IMAGE(@"ic_bigmore") forState:UIControlStateNormal];
//    [self.moreButton setImage:IMAGE(@"ic_more_up") forState:UIControlStateSelected];
//    [self.moreButton setTitle:@"更多选填项" forState:UIControlStateNormal];
//    [self.moreButton setTitle:@"收起更多选填项" forState:UIControlStateSelected];
//    [self.moreButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
//    [aView addSubview:self.moreButton];
    
//    aView.backgroundColor = UIColorFromRGB(0xF2F5FA);
    self.tableView.tableFooterView = [[UIView alloc]init];
    self.tableView.estimatedRowHeight = 117.0f;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
        self.titleArrData = @[@"基本信息",@"自我描述",@"工作经验",@"教育经历",@"项目经历",@"技能评价"];
//    self.titleArrData = @[@"基本信息",@"工作经验"];
    
    //获取企业文化列表
}
-(void)buttonClick:(UIButton *)sender{
    sender.selected = !sender.selected;
    
    if (sender.selected) {
        self.titleArrData = @[@"基本信息",@"自我描述",@"工作经验",@"教育经历",@"项目经历",@"技能评价"];
    }else{
        self.titleArrData = @[@"基本信息",@"自我描述"];
    }
    [self.tableView reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.titleArrData.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {

        
        return 1;
    }else if (section == 1) {
        /**自我描述*/
        if (self.modelUserInfoResume.seltDescription.length==0) {
            return 0;
        }else{
            return 1;
        }
    }else if (section == 2) {
        /**工作经历*/
        if (self.workExperienceArr.count==0) {
            return 0;
        }else{
            return 1;
        }
    }else if (section == 3) {
        /**教育经历*/
        if (self.educationArr.count==0) {
            return 0;
        }else{
           
            return 1;
        }
        
    }
    else if (section == 4) {
        /**项目经验*/
        if (self.projectArr.count==0) {
            return 0;
        }else{

            return 1;
        }
    }else if (section ==5) {
        /**技能评价*/
        if (self.skillArr.count==0) {
            return 0;
        }else{
            return 1;
        }
    }
    else{

        return 0;
    }
}

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 117;
//}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        /**基本信息*/
        static NSString *identifier = @"PreviewBaseInfoTableViewCell";
        PreviewBaseInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        cell.selectionStyle =  UITableViewCellSelectionStyleNone;
        [cell getModelGetResume:self.modelUserInfoResume];
        
        return cell;
    }else if (indexPath.section == 1) {
        /**自我描述*/
        
        if (self.modelUserInfoResume.seltDescription.length==0) {
            static NSString *identifier = @"NoVitaeTableViewCell";
            NoVitaeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            cell.labWorkExp.text = @"添加自我描述";
            [cell.editButton removeTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];
            [cell.editButton addTarget:self action:@selector(describeEdit:) forControlEvents:UIControlEventTouchUpInside];
            return cell;
        }else{
            static NSString *identifier = @"RemarksTableViewCell";
            RemarksTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            cell.remarkLabel.text = self.modelUserInfoResume.seltDescription;
            //            [cell.editButton addTarget:self action:@selector(describeEdit:) forControlEvents:UIControlEventTouchUpInside];
            return cell;
        }
    }else if (indexPath.section == 2) {
        /**工作经历*/
        if (self.workExperienceArr.count==0) {
            static NSString *identifier = @"NoVitaeTableViewCell";
            NoVitaeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            cell.labWorkExp.text = @"添加工作经验";
            [cell.editButton removeTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];
            [cell.editButton addTarget:self action:@selector(workExperienceEdit:) forControlEvents:UIControlEventTouchUpInside];
            return cell;
        }else{
            static NSString *identifier = @"WorkExperienceTableViewCell";
            WorkExperienceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            cell.workExperienceArr = self.workExperienceArr;
            return cell;
        }
    }else if (indexPath.section == 3) {
        /**教育经历*/
        if (self.educationArr.count==0) {
            static NSString *identifier = @"NoVitaeTableViewCell";
            NoVitaeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            cell.labWorkExp.text = @"添加教育经历";
            [cell.editButton removeTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];
            [cell.editButton addTarget:self action:@selector(educationEdit:) forControlEvents:UIControlEventTouchUpInside];
            return cell;
        }else{
            static NSString *identifier = @"EducationTableViewCell";
            EducationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            cell.educationArr = self.educationArr;
            [cell.editButton addTarget:self action:@selector(educationEdit:) forControlEvents:UIControlEventTouchUpInside];
            return cell;
        }
        
    }
    else if (indexPath.section == 4) {
        /**项目经验*/
        if (self.projectArr.count==0) {
            static NSString *identifier = @"NoVitaeTableViewCell";
            NoVitaeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            cell.labWorkExp.text = @"添加项目经历";
            [cell.editButton removeTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];
            [cell.editButton addTarget:self action:@selector(projectExperienceEdit:) forControlEvents:UIControlEventTouchUpInside];
            return cell;
        }else{
            static NSString *identifier = @"ProjectExperienceTableViewCell";
            ProjectExperienceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            cell.projectArr = self.projectArr;
            [cell.editButton addTarget:self action:@selector(projectExperienceEdit:) forControlEvents:UIControlEventTouchUpInside];
            return cell;
        }
    }else if (indexPath.section ==5) {
        /**技能评价*/
        if (self.skillArr.count==0) {
            static NSString *identifier = @"NoVitaeTableViewCell";
            NoVitaeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            cell.labWorkExp.text = @"添加技能评价";
            [cell.editButton removeTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];
            [cell.editButton addTarget:self action:@selector(skillEdit:) forControlEvents:UIControlEventTouchUpInside];
            return cell;
        }else{
            static NSString *identifier = @"SkillTableViewCell";
            SkillTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            cell.skillArr = self.skillArr;
            //            [cell.editButton addTarget:self action:@selector(skillEdit:) forControlEvents:UIControlEventTouchUpInside];
            return cell;
        }
    }
    else{
        static NSString *identifier = @"NoVitaeTableViewCell";
        NoVitaeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        cell.selectionStyle =  UITableViewCellSelectionStyleNone;
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 45.0f;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    static NSString *identifier = @"VitaeTitleHeadView";
    VitaeTitleHeadView *headView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:identifier];
    headView.backgroundColor = UIColorFromRGB(0xf2f4f5);
    headView.contentView.backgroundColor = UIColorFromRGB(0xf2f4f5);
    headView.titleLabel.text = self.titleArrData[section];

    
    headView.editView.hidden = YES;
    headView.mustLabel.hidden = YES;
    
    
    return headView;
    
}

- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    
}


- (void)btnValuesOnClick:(UIButton *)btn{
    
    
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
